package com.wzw.service.impl;

import com.wzw.dao.IUserDao;
import com.wzw.dao.MYBeanFactory;
import com.wzw.dao.MyInstanceFactory;
import com.wzw.dao.impl.UserDao;
import com.wzw.proxy.JdkProxy;
import com.wzw.service.IMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MainService implements IMainService{

    //先匹配类型，后匹配名称，都找不到会报错
    @Resource
   // @Autowired
    private IUserDao dao = null;

    public MainService(){

    }

//    public IUserDao getDao(){
//        //正常情况下 : 第一种方法
//        userDao = new UserDao();
//        // 二
//        userDao = MYBeanFactory.getBean();
//        // 三
//        //dao = MyInstanceFactory.getBean();
//
//        //spring 框架下 ：
//        return userDao;
//    }

    public String login() {
        JdkProxy proxy = new JdkProxy();
        IUserDao myDao = (IUserDao) proxy.createProxy(dao);

        return myDao.find();
    }
}
